package com.wangcang.widgetlibrary.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.activity.base.BaseActivity;
import com.wangcang.widgetlibrary.media.ClipImageLayout;

public class ClipImageActivity extends BaseActivity implements View.OnClickListener {
    private TextView mTopCancel, mTopOk;
    private ClipImageLayout mClipImageLayout;
    private ImageView mClipImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_clip_image);

        initView();
        initEvent();
    }

    private void initView() {
        mTopCancel = findView(R.id.top_cancel);
        mTopOk = findView(R.id.top_ok);

        mClipImageLayout = findView(R.id.clip_image_layout);
        mClipImageView = findView(R.id.clip_image_view);
    }

    private void initEvent() {
        mTopCancel.setOnClickListener(this);
        mTopOk.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_cancel:
                finishActivity();
                break;
            case R.id.top_ok:
                Bitmap bitmap = mClipImageLayout.clip();

                mClipImageLayout.setVisibility(View.GONE);
                mClipImageView.setVisibility(View.VISIBLE);

                mClipImageView.setImageBitmap(bitmap);
                break;
            default:
                break;
        }
    }
}
